Ext.define('Admin.view.runtime.TableChartController', {
			extend : 'Admin.app.BaseController',
			alias : 'controller.tablechart',

			p1dMatirx : function() {
				return {
					leftAxis : [{
								dataIndex : 'hour',
								width : 95,
								align : 'center',
								header : '时'
							}],

					topAxis : [{
								dataIndex : 'minute',
								width : 85,
								align : 'right',
								header : '分'
							}]
				}
			},

			p1mMatrix : function() {
				return {
					leftAxis : [{
								dataIndex : 'ten',
								width : 95,
								align : 'center',
								header : '十'
							}],

					topAxis : [{
								dataIndex : 'single',
								width : 85,
								align : 'right',
								header : '日'
							}]
				}
			},

			p1yMatirx : function() {
				return {
					leftAxis : [{
								dataIndex : 'day',
								width : 85,
								align : 'center',
								header : '日'
							}],

					topAxis : [{
								dataIndex : 'month',
								width : 95,
								align : 'right',
								header : '月'
							}]
				}
			},

			dateStepOfInterval : function() {
				var vm = this.getViewModel(), interval = vm.get('interval');
				switch (interval) {
					case 'P1M' :
						return Ext.Date.MONTH;
						break;
					case 'P1Y' :
						return Ext.Date.YEAR;
					default :
						return Ext.Date.DAY;
				}
			},

			onPrevClick : function(btn) {
				var me = this, vm = me.getViewModel(), date = vm.get('date');
				vm.set('date', Ext.Date.add(date, me.dateStepOfInterval(), -1));
			},

			onNextClick : function(btn) {
				var me = this, vm = me.getViewModel(), date = vm.get('date');
				vm.set('date', Ext.Date.add(date, me.dateStepOfInterval(), 1));
			},

			getExtraParams : function(interval, params) {
				var vm = this.getViewModel(), record = vm.get('record');
				return {
					id : record.data.id,
					level : record.data.level,
					date : Ext.Date.format(params && params.date ? params.date : vm.get('date'), 'Y-m-d'),
					interval : interval ? interval : vm.get('interval')
				};
			},

			disableChartLayout : function() {
				var chart = this.getView().queryById('chart');
				chart.disableLayouts = true;
			},

			onIntervalChange : function(cmp, newValue, oldValue, eOpts) {
				var me = this, vm = me.getViewModel(), pivot = this.getView(), matrix;
				me.disableChartLayout();
				switch (newValue) {
					case 'P1M' :
						matrix = me.p1mMatrix();
						break;
					case 'P1Y' :
						matrix = me.p1yMatirx();
						break;
					default :
						matrix = me.p1dMatirx();
				}
				matrix && pivot.queryById('pivot').reconfigurePivot(matrix);
				oldValue && me.refreshOfCard(null, newValue, null);
			},

			onCardChange : function(cmp, newValue, oldValue, eOpts) {
				var me = this;
				me.disableChartLayout();
				newValue && oldValue && me.refreshOfCard(newValue, null, null);
			},

			onRefreshDefault : function(view, record, params) {
				this.refreshOfCard(null, null, params);
			},

			refreshChart : function(extraParams) {
				var url = {
					url : '/rest/rpt/data/chart',
					params : extraParams
				}
				this.getViewModel().set('echartUrl', url);
			},

			refreshPivot : function(extraParams) {
				var store = this.getStore('pivotStore');
				store.getProxy().extraParams = extraParams;
				store.reload();
			},

			refreshOfCard : function(card, interval, params) {
				var me = this, extraParams = me.getExtraParams(interval, params);

				if (extraParams) {
					card = card || me.getViewModel().get('activeCard');
					switch (card) {
						case 'chart' :
							me.refreshChart(extraParams);
							break;
						case 'pivot' :
							me.refreshPivot(extraParams);
					}
				}
			}
		});